package com.ts.animal.controller;

import com.ts.animal.domain.WarningRecordDO;
import com.ts.animal.service.WarningRecordService;
import com.ts.common.utils.PageInfos;
import com.ts.common.utils.PageUtils;
import com.ts.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 预警记录
 *
 * @author bobby
 * @email bobby@126.com
 * @date 2022-09-02 16:17:49
 */

@Controller
@RequestMapping("/animal/warningRecord")
public class WarningRecordController {
    @Autowired
    private WarningRecordService warningRecordService;

    @GetMapping()
    @RequiresPermissions("animal:warningRecord:warningRecord")
    String WarningRecord() {
        return "animal/warningRecord/warningRecord";
    }

    @ResponseBody
    @RequestMapping("/list")
    @RequiresPermissions("animal:warningRecord:warningRecord")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        PageUtils pageUtils = new PageInfos(params) {
            public List inject(Map params) {
                return warningRecordService.list(params);
            }
        }.query().lowerUnderscore();
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("animal:warningRecord:add")
    String add() {
        return "animal/warningRecord/add";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("animal:warningRecord:edit")
    String edit(@PathVariable("id") Integer id, Model model) {
        WarningRecordDO warningRecord = warningRecordService.get(id);
        model.addAttribute("warningRecord", warningRecord);
        return "animal/warningRecord/edit";
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("animal:warningRecord:add")
    public Result save(WarningRecordDO warningRecord) {
        Result result = Result.ok();
        warningRecordService.save(result, warningRecord);
        return result;
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("animal:warningRecord:edit")
    public Result update(WarningRecordDO warningRecord) {
        Result result = Result.ok();
        warningRecordService.update(result, warningRecord);
        return result;
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("animal:warningRecord:remove")
    public Result remove(Integer id) {
        Result result = Result.ok();
        warningRecordService.remove(result, id);
        return result;
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("animal:warningRecord:batchRemove")
    public Result remove(@RequestParam("ids[]") Integer[] ids) {
        Result result = Result.ok();
        warningRecordService.batchRemove(result, ids);
        return result;
    }

    /**
     * 出发告警推送
     */
    @GetMapping("/pushWarnInfoToWeb")
    @ResponseBody
    public Result pushWarnInfoToWeb() {
        Result result = Result.ok();
        warningRecordService.pushWarnInfoToWeb();
        return result;
    }
    /**
     * 处理预警/告警
     */
    @GetMapping("/handleWarn")
    @ResponseBody
    public Result handleWarn() {
        Result result = Result.ok();
        warningRecordService.handleWarn();
        return result;
    }

}
